package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.TwoProblem;
import cn.pugle.oj.catalog.Unknown;

/**
 * https://leetcode.com/problems/container-with-most-water
 * 接雨水是 LC42
 *
 * @author tzp
 * @since 2020/12/15
 */
public class LC11 implements TwoProblem {

    public int maxArea(int[] height) {
        if (height == null || height.length <= 1) return 0;
        int left = 0, right = height.length - 1;
        int max = Integer.MIN_VALUE;
        while (left < right) {
            max = Math.max(max, (right - left) * Math.min(height[left], height[right]));
            if (height[left] > height[right]) {
                right--;
            } else {
                left++;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int[] x = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        System.out.println(new LC11().maxArea(x));
    }
}
